package com.panda.mall.order.info.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panda.mall.common.mallOrder.dto.QueryOrderDto;
import com.panda.mall.common.mallOrder.entity.MallOrder;
import com.panda.mall.common.result.Result;
import com.panda.mall.order.info.service.MallOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * author: tcy
 * createDate: 2022/10/13
 * description:
 */
@Api(tags = "商品订单信息")
@RestController
@RequestMapping("/order")
public class MallOrderController {

    @Autowired
    MallOrderService mallOrderService;

    @ApiOperation(value = "获取订单编号", notes = "获取订单编号")
    @GetMapping("/generateOrderNumber")
    public Result<String> generateOrderNumber() {
        return Result.success(mallOrderService.generateOrderNumber());
    }

    @ApiOperation(value = "查询订单（分页）", notes = "分页查询订单")
    @PostMapping("/info/listOrders")
    public Result<Page<MallOrder>> listOrders(@RequestBody QueryOrderDto dto) {
        return Result.success(mallOrderService.listOrders(dto));
    }

    @ApiOperation(value = "查询订单", notes = "查询订单")
    @PostMapping("/info/queryOrders")
    public Result<List<MallOrder>> queryOrders() {
        return Result.success(mallOrderService.queryOrders());
    }

    @ApiOperation(value = "按id查询订单", notes = "按id查询订单")
    @GetMapping("/info/queryOrderById/{id}")
    public Result<MallOrder> queryOrderById(@PathVariable("id") Long id) {
        return Result.success(mallOrderService.queryOrderById(id));
    }

    @ApiOperation(value = "新增订单", notes = "新增订单")
    @PostMapping("/info/saveOrder")
    public Result<Boolean> saveOrder(@RequestBody MallOrder order) {
        return Result.success(mallOrderService.saveOrder(order));
    }

    @ApiOperation(value = "修改订单", notes = "修改订单")
    @PostMapping("/info/updateOrder")
    public Result<Boolean> updateOrder(@RequestBody MallOrder order) {
        return Result.success(mallOrderService.updateOrder(order));
    }

    @ApiOperation(value = "删除订单", notes = "删除订单")
    @PostMapping("/info/deleteOrder")
    public Result<String> deleteOrder(@RequestBody List<Long> ids) {
        return Result.success(mallOrderService.deleteOrder(ids));
    }

}
